
import React from 'react'
import './CouponManagement.css'
import NewCouponsHoc from '../../../component/promotion/hoc/NewCouponsHoc'
import { inject,observer} from 'mobx-react'
import AddYouHuiJuan from "../../../component/promotion/AddYouHuiJuan";
import {Button} from 'antd'



import { DatePicker, Radio, Space  } from 'antd';
import { withRouter } from 'react-router-dom';


const { RangePicker } = DatePicker;


@NewCouponsHoc
@withRouter
@inject('xinJianYouHuiJuan')
@observer

class NewCoupons extends React.Component {

    state = {
        size: 'default',
    };

    handleSizeChange = e => {
        this.setState({ size: e.target.value });
    };


    changeMobx = (data)=>{
        return (set)=>this.props.xinJianYouHuiJuan.insertStart(data,set)
    }


    render() {
        const { size } = this.state;
        let {myFrom,insertStart} = this.props.xinJianYouHuiJuan
        let myMethodData = ()=>{//点击确认，提交表单，如果返回200，那么返回优惠卷管理页面，如果失败就不跳转
            this.props.xinJianYouHuiJuan.myMethodData().then(data=>{
                if(data === 200)this.props.history.push("/Home/cuXiao/CouPon/youhuijuanGuanLi")
            })
        }
        return (
            <div className="NewCoupons">
                <div className="itemContent">

                    <div className="itemContentRow">
                        <span>优惠劵名称：</span>
                        <input value={myFrom.couponName} onChange={this.changeMobx('couponName')} type="text" />
                    </div>

                    <div className="itemContentRow">
                        <span>类型:</span>
                        <Radio.Group name="radiogroup" onChange={this.changeMobx('couponType')} defaultValue={myFrom.couponType}>
                            <Radio value={1}><span>用户发放</span></Radio>
                            <Radio value={2}><span>商品发放</span></Radio>
                            <Radio value={5}><span>订单发放</span></Radio>
                            <Radio value={3}><span>线下发放</span></Radio>
                            <Radio value={4}><span>关注发放</span></Radio>
                            <Radio value={6}><span>团长优惠</span></Radio>
                            <Radio value={7}><span>积分兑换</span></Radio>
                        </Radio.Group>
                    </div>

                    <AddYouHuiJuan bangDing={this.changeMobx}/>
                   

                    <div className="itemContentRow">
                        <span>发放日期</span>
                        <Space direction={myFrom.stateDate} size={12}>
                            <RangePicker onChange={this.changeMobx('stateDate')} size={size} />
                        </Space>
                    </div>

                    <div className="itemContentRow">
                        <span>有效日期：</span>
                        <Space direction={myFrom.effectiveDate} size={12}>
                            <RangePicker onChange={this.changeMobx('effectiveDate')} size={size} />
                        </Space>
                    </div>

                    <div className="itemContentRow">
                        <Button type="primary"  onClick={myMethodData}>确定</Button>
                    </div>
                </div>
            </div>

        )
    }
}

export default NewCoupons